package com.pjedu.springbootquick01.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.pjedu.springbootquick01.entity.MySqlEntity;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @Author 汪洋
 * @Description
 */
@Configuration
public class DataSourceConfig {
    /*@Resource
    private MySqlEntity mySqlEntity;

    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(mySqlEntity.getDriverClassName());
        dataSource.setUrl(mySqlEntity.getUrl());
        dataSource.setUsername(mySqlEntity.getUsername());
        dataSource.setPassword(mySqlEntity.getPassword());
        return dataSource;
    }*/

    @Bean
    @ConfigurationProperties(prefix = "mysql")
    public DataSource dataSource(MySqlEntity mySqlEntity) {
        return new DruidDataSource();
    }
}
